package com.example.administrator.zkdemo.db.orm.manager;

/**
 * Created with Android Studio.
 * 描述: ${DESCRIPTION}
 * Date: 2018/11/22
 * Time: 14:27
 *
 * @author 晏琦云
 * @version ${VERSION}
 */

import android.content.Context;
import android.database.CursorWrapper;
import android.net.Uri;
import android.util.Log;

import com.zkteco.android.util.serialization.Serializer;
import com.zkteco.android.util.serialization.SerializerFactory;

import java.io.IOException;
import java.util.Arrays;

public final class CoreProvider
        implements Provider {
    private static final String CONTENT_PROVIDER_URI = "content://com.zkteco.android.core/";
    private static final String TAG = "CoreProvider";
    private final Context context;
    private final Serializer serializer = SerializerFactory.INSTANCE.getDefaultSerializer();

    public CoreProvider(Context paramContext) {
        this.context = paramContext;
    }

    public void close()
            throws IOException {
    }

    public Object invoke(String paramString, Object[] paramArrayOfObject) {
        Object localObject1 = TAG;
        Object localObject2 = new StringBuilder();
        ((StringBuilder) localObject2).append("Invoking function ");
        ((StringBuilder) localObject2).append(paramString);
        ((StringBuilder) localObject2).append("; parameters: ");
        ((StringBuilder) localObject2).append(Arrays.toString(paramArrayOfObject));
        Log.d((String) localObject1, ((StringBuilder) localObject2).toString());
        localObject1 = new StringBuilder();
        ((StringBuilder) localObject1).append("content://com.zkteco.android.core/");
        ((StringBuilder) localObject1).append(paramString);
        Uri localUri = Uri.parse(((StringBuilder) localObject1).toString());
        if (paramArrayOfObject != null) {
            int j = paramArrayOfObject.length;
            localObject2 = new String[j];
            int i = 0;
            while (true) {
                localObject1 = localObject2;
                if (i >= j)
                    break;
                if (paramArrayOfObject[i] == null)
                    localObject2[i] = null;
                else
                    localObject2[i] = this.serializer.getStringFromInstance(paramArrayOfObject[i]);
                i += 1;
            }
        }
        localObject1 = null;
        paramArrayOfObject = TAG;
        localObject2 = new StringBuilder();
        ((StringBuilder) localObject2).append("Invoking function ");
        ((StringBuilder) localObject2).append(paramString);
        ((StringBuilder) localObject2).append("; projection: ");
        ((StringBuilder) localObject2).append(Arrays.toString(localObject1));
        Log.d(paramArrayOfObject, ((StringBuilder) localObject2).toString());
        return CursorWrapper.unwrapFromCursor(this.context.getContentResolver().query(localUri, localObject1, null, null, null));
    }
}
